<template>
  <div class="date-teacher">
    <el-row :gutter="1" type="flex" justify="center" style="width:100%;">
      <el-col>
        <el-input v-model="name" placeholder="教师名称" style="width:200px;" @keyup.enter.native="handleFilter"/>
        <el-button type="primary" @click="handleFilter">搜索</el-button>
        <el-button size="medium" type="info" @click="clearParams">清空</el-button>
      </el-col>
    </el-row>
    <eltable
      :table-label="tableLabel"
      :table-data="tableData.slice((currentpage-1)*pagesize,currentpage*pagesize)"
    >
      <el-table-column slot="first" label="老师名称" align="center" min-width="20">
        <template slot-scope="scope">
          <el-button type="text">{{ scope.row.teacherName }}</el-button>
        </template>
      </el-table-column>
      <el-table-column slot="isEnd" label="取消预约课次" align="center" min-width="10">
        <template slot-scope="scope">
          <el-button type="text">{{ scope.row.cancleNum }}</el-button>
        </template>
      </el-table-column>
      <el-table-column slot="button" label="操作" align="center" min-width="10">
        <template slot-scope="scope">
          <el-button type="primary" @click="detail(scope)">详情</el-button>
        </template>
      </el-table-column>
    </eltable>
    <pagination
      :total="total"
      :current-page="currentpage"
      :page-size="pagesize"
      @handleSizeChange="handleSizeChange"
      @handleCurrentChange="handleCurrentChange"
    />
  </div>
</template>

<script>
import Eltable from '@/components/Eltable'
import Pagination from '@/components/Pagination'
import { getTeacherList, getTeacherDetail } from '@/api/subject/course' // 数据接口
import { getTenantId } from '@/utils/auth'
export default {
  components: {
    Eltable,
    Pagination
  },
  data() {
    return {
      total: 3,
      currentpage: 1,
      pagesize: 10,
      name: '',
      tableLabel: [
        {
          label: '可预约课次', width: '10', prop: 'reserveNum'
        },
        {
          label: '已预约课次', width: '10', prop: 'bespeakNum'
        },
        {
          label: '已完成课次', width: '10', prop: 'finishNum'
        }
      ],
      tableData: [],
      listFilter: []
    }
  },
  mounted() {
    this.getData()
  },
  methods: {
    handleSizeChange(val) {
      this.currentpage = 1
      this.pagesize = val.value
      if (this.pagesize >= 20) {
        scrollTo(50, 800)
      }
    },
    handleCurrentChange(val) {
      this.currentpage = val.value
      if (this.pagesize >= 20) {
        scrollTo(50, 800)
      }
    },
    getData() {
      getTeacherList(getTenantId()).then(res => {
        this.tableData = res.data.items
        this.listFilter = res.data.items
        this.total = res.data.items.length
      })
    },
    handleFilter() {
      this.tableData = this.listFilter.filter(item => {
        if (this.name && item.teacherName.toLocaleLowerCase().indexOf(this.name.toLocaleLowerCase()) === -1) return false
        return true
      })
      this.total = this.tableData.length
    },
    clearParams() {
      this.name = ''
      this.getData()
    },
    detail(scope) {
      getTeacherDetail(scope.row.teacherId).then(res => {
        console.log(res.data.items)
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.date-teacher {
  margin-top: 0px;
  width: 100%;
  // padding: 14px 20px 21px 20px;
  .list {
    height: 110px;
    text-align: center;
  }
  .search {
    margin-top: 5px;
    padding: 15px 20px;
    background-color: #e5e7ea;
    border-radius: 5px;
  }
}
</style>
